#include "../include/rpcServer.h"
#include "../include/services.h"
#include <mutex>
#include "../include/conf_reader.h"
void rpcServer::start()
{
    static std::once_flag flag;
    std::call_once(flag,[this](){
        this->server=build.BuildAndStart();
        this->server->Wait();   //阻塞开启
    });

}

void rpcServer::stop()
{

    this->server->Shutdown();
}


rpcServer::rpcServer(){
    //增加监听端口
    std::string ip_port=conf_reader::get_conf_reader_instance()->get_value_from_key("varifyCode","192.168.174.139:9999");
    std::cout<<"rpc本服务接收连接的ip与端口："<<ip_port<<std::endl;
    build.AddListeningPort(ip_port.c_str(),grpc::InsecureServerCredentials());

    register_services();
    std::cout<<"成功注册相应的服务"<<std::endl;
}


void rpcServer::register_services()
{
    this->_userCenterServices=new userCenterServices();
    build.RegisterService(_userCenterServices);

}

rpcServer::~rpcServer()
{
    delete _userCenterServices;
}